// import 'dart:nativewrappers/_internal/vm/lib/ffi_native_type_patch.dart';

import 'package:auto_route/auto_route.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../providers/auth_provider.dart';

@RoutePage()
class HomeTab extends StatelessWidget {
  const HomeTab({super.key});

  @override
  Widget build(BuildContext context) {
    return CupertinoPageScaffold(
      navigationBar: const CupertinoNavigationBar(middle: Text('首页')),
      child: SafeArea(
        child: GridView.builder(
          gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 2, // 两列网格
            crossAxisSpacing: 16, // 列间距
            mainAxisSpacing: 16, // 行间距
            childAspectRatio: 0.7, // 宽高比控制
          ),
          padding: EdgeInsets.all(16), // 整体边距
          itemCount: 10, // 数据总量（必须）
          itemBuilder: (context, index) {
            // 动态构建子项
            return _buildCharacterCard();
          },
        ),
      ),
    );
  }

  Widget _buildCharacterCard() {
    return Container(
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(16),
        boxShadow: [
          BoxShadow(
            color: Colors.black12,
            blurRadius: 10,
            offset: Offset(0, 4),
          ),
        ],
      ),
      child: ClipRRect(
        borderRadius: BorderRadius.circular(16),
        child: Stack(
          children: [
            // 背景图片
            Positioned.fill(
              child: Image.network(
                "https://c-ssl.dtstatic.com/uploads/blog/202404/06/2YSBZ10AU6XYyvG.thumb.1000_0.jpeg",
                fit: BoxFit.cover,
              ),
            ),

            // 顶部表情符号
            Positioned(
              top: 12,
              left: 12,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  Text("昵称"),
                  Icon(Icons.circle_notifications_outlined, color: Colors.cyan),
                ],
              ),
            ),

            // // POPULAR标签
            // if (data.specialTag != null)
            //   Positioned(
            //     top: 12,
            //     right: 12,
            //     child: Container(
            //       padding: EdgeInsets.symmetric(horizontal: 8, vertical: 4),
            //       decoration: BoxDecoration(
            //         color: Colors.orange,
            //         borderRadius: BorderRadius.circular(20),
            //       ),
            //       child: Text(
            //         data.specialTag!,
            //         style: TextStyle(
            //           color: Colors.white,
            //           fontWeight: FontWeight.bold,
            //           fontSize: 12,
            //         ),
            //       ),
            //     ),
            //   ),

            // 底部信息区
            Positioned(
              bottom: 0,
              left: 0,
              right: 0,
              child: Container(
                height: 80,
                decoration: BoxDecoration(
                  gradient: LinearGradient(
                    begin: Alignment.bottomCenter,
                    end: Alignment.topCenter,
                    colors: [Colors.black54, Colors.transparent],
                  ),
                ),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.end,
                  children: [
                    // 摄像机图标
                    Container(
                      width: 40,
                      height: 40,
                      decoration: BoxDecoration(
                        color: Colors.purple,
                        shape: BoxShape.circle,
                      ),
                      child: Icon(Icons.videocam, color: Colors.white),
                    ),
                    SizedBox(height: 8),
                    // 姓名
                    Text(
                      "姓名",
                      style: TextStyle(
                        color: Colors.white,
                        fontSize: 18,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

class HomeListPage extends StatefulWidget {
  const HomeListPage({super.key});

  @override
  State<HomeListPage> createState() => _HomeListPageState();
}

class _HomeListPageState extends State<HomeListPage> {
  @override
  Widget build(BuildContext context) {
    return const Placeholder();
  }
}
